home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * mainXTRNdemo.c: demo version of an external code resource
- * © 1994 Jersey Scientific, All Rights Reserved
- *
- * Notes:
- * Use SetupA4 if you want to use globals in your program. However,
- * after you do a "merge" or rebuild of your external, the new
- * code resource that loads will have null globals.
- * History:
- * 01/01/94: Version 1 of xtern structure
- * 06/05/94: More stuff
- */
-
- #include <SetUpA4.h>
- //#include "CallKeyEquivalents.h"
- //#include "CallKeyFunctions.h"
- #include "XTRN.h"
-
- Boolean
- main(
- short type, // type of call (XTRN_xxxx, see above)
- XtrnPtr xP, // xtern structure
- XtItemPtr iP, // some fields are for your private use - see above
- short keys // modifier keys associated with this event (KEY, MENU, and ZOOM only)
- // - or the event return code
- ) {
- char *fp;
- unsigned char len, j;
- long start, end;
- Handle h;
- Str255 foop;
- TextDataPtr tdP;
- Boolean retCode;
-
- RememberA0();
- SetUpA4();
-
- retCode = FALSE; // default return value
-
- // decide what to do based on the action
- switch(type) {
- case XTRN_INIT:
- // better to not call CMaster callbacks here
- // maybe allocate some free memory
- //iP->reserved0 = (long)NewHandleClear(256);
- //if(iP->reserved0 == 0)
- // (*xP->debugPrintf)("NO MEMORY!!!");
- // maybe get a preference resource
- //iP->reserved1 = (long)GetResource('PREF', resID);
-
- iP->wantRawEvents = TRUE;
- goto ret; // any value OK
-
- case XTRN_QUIT:
- // better to not call CMaster callbacks here
- //if(iP->reserved0 != 0)
- // DisposeHandle((Handle)iP->reserved0);
- goto ret; // any value OK
-
- case XTRN_RAW:
- case XTRN_COOKED:
- // only should get these if you set the xP->... parameter to !FALSE
-
- // if testing for the first time, you might want to add this line so that
- // - your action only takes effect if the CAPSLOCK key is depressed. Then,
- // - if you have a coding bug you won't have to go to great lengths to get
- // - THINK sane if you have a bug and eat all events, etc...
- if(CAPSLOCK){
- short mods, key;
- if(xP->evp->what == keyDown) {
- mods = xP->evp->modifiers & (cmdKey|optionKey|controlKey|shiftKey);
- key = xP->evp->message & charCodeMask;
- if(mods == 0 && (key == 'X' || key == 'x'))
- SysBeep(1);
- }
- }
- // your code goes here
- // ...
- retCode = (Boolean)keys; // return what was passed to us
- goto ret; // any value OK
-
- case XTRN_WIND_OPEN1_SIZE:
- case XTRN_WIND_OPEN2_DATA:
- SysBeep(1);
- // only should get these if you set the xP->... parameter to !FALSE
- // use getTextData() to get file info on current window (so you could
- // - open the resource fork of the file if necessary
- goto ret; // any value OK
-
- case XTRN_WIND_CLOSE:
- SysBeep(1);
- // only should get these if you set the xP->... parameter to !FALSE
- // use getTextData() to get file info on current window (so you could
- // - open the resource fork of the file if necessary
- goto ret;
-
- case XTRN_KEY:
- case XTRN_MENU:
- break; // handle below
-
- case XTRN_ZOOM:
- // change the userState or stdState rects in the window->dataHandle
- // return 0, inZoomIn, or inZoomOut (from windows.h)
- // 0 sayslet whatever would have happened, happen
- // inZoomIn and inZoomOut tell CMaster where to zoom the window
- goto ret; // any value OK
- }
-
- // now, look at the key modifiers
- switch(keys) {
- case 0:
- #ifdef Get_All_Files_And_Show_Them
- {
- FSSpec *fsspP;
- short xxx;
- Str255 str;
- Boolean ret;
-
- ret = (*xP->getFiles)(xP->window, FILES_HEADER, &fsspP, &xxx);
- str[0] = (*xP->sprintf)((char *)&str[1], "Ret was %d num %d", ret, xxx);
- ParamText(str, str, str, str);
- (*xP->positionSubDialog)('ALRT', xP->resID);
- NoteAlert(xP->resID, (void *)0);
- }
- #endif
- SysBeep(1);
- break;
- case (optionKey):
- (*xP->softBeep)();
- break;
- case (cmdKey):
- (*xP->hardBeep)();
- break;
- case (controlKey):
- (*xP->doneBeep)();
- break;
- case (shiftKey):
- tdP = (*xP->getTextData)(xP->window);
- if(tdP != (void *)0) {
- start = tdP->startSelect;
- end = tdP->endSelect;
- h = tdP->text;
-
- len = end - start;
- if(len == 0) {
- SysBeep(1);
- goto ret; // any value OK
- }
- fp = *h + start;
- for(foop[0]=len, j=0; len--; )
- foop[++j] = *fp++;
-
- ResetAlrtStage();
- ParamText(foop, foop, foop, foop);
- (*xP->positionSubDialog)('ALRT', xP->resID);
- NoteAlert(xP->resID, (void *)0);
- DisposePtr((Ptr)tdP);
- }
- break;
- case (shiftKey|optionKey):
- break;
- case (shiftKey|cmdKey):
- break;
- case (optionKey|cmdKey):
- break;
- case (optionKey|controlKey):
- break;
- case (optionKey|shiftKey|cmdKey):
- // supposed you changed your PREF resource here
- // ChangeResource('PREF', resID);
- // UpdateResFile(xP->xtrnResFile);
- break;
- }
-
- // return FALSE to effectively "eat" the event. If you changed the event
- // - (say a NULLEVENT to something else), then return TRUE.
- ret:
- RestoreA4();
- return retCode;
- }